package com.ants.boot.system.controller;

import com.ants.boot.core.Response;
import com.ants.boot.core.annotation.Log;
import com.ants.boot.model.BaseController;
import com.ants.boot.system.dto.sysrole.*;
import com.ants.boot.system.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 蚂蚁会花呗
 * @date 2022/3/9 15:22
 */
@RestController
@RequestMapping("/system/sye_role")
@Api(tags = "角色管理")
public class SysRoleController extends BaseController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 角色信息分页搜索查询
     * @param dto
     * @return
     */
    @PostMapping("page_info")
    @Log(module = "角色信息",operate = "分页搜索查询")
    @ApiOperation(value = "列表搜索查询",notes = "查询、搜索、分页")
    public Response pageInfo(@RequestBody @Validated QueryRoleDto dto){
        return Response.okData(sysRoleService.pageInfo(dto));
    }

    /**
     * 更新角色
     * @return
     */

    @PostMapping("update_role")
    @Log(module = "角色信息",operate = "更新角色")
    @ApiOperation(value = "更新角色",notes = "更新角色")
    public Response updateRole(@RequestBody @Validated UpdateRoleDto dto){
        return sysRoleService.updateRole(dto);
    }


    /**
     * 新增角色
     * @return
     */

    @PostMapping("add_role")
    @Log(module = "角色信息",operate = "新增角色")
    @ApiOperation(value = "新增角色",notes = "新增角色")
    public Response updateRole(@RequestBody @Validated AddRoleDto dto){
        return sysRoleService.addRole(dto);
    }

    /**
     * 删除和批量删除
     * @param dto
     * @return
     */
    @PostMapping("del_role")
    @Log(module = "角色信息",operate = "删除角色")
    @ApiOperation(value = "删除角色",notes = "删除角色")
    public Response delRole(@RequestBody @Validated DelRoleDto dto){
        boolean result = sysRoleService.delRole(dto.getIds());
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

    /**
     * 更新状态
     * @param dto
     * @return
     */
    @PostMapping("update_status")
    @Log(module = "角色信息",operate = "修改状态")
    @ApiOperation(value = "修改状态",notes = "修改状态")
    public Response updateStatus(@RequestBody @Validated UpdateStatusDto dto){
        boolean result = sysRoleService.updateStatus(dto.getId(),dto.getStatus());
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

    /**
     * 查询没有被删除的角色信息列表
     * @return
     */
    @GetMapping("list_role_not_remove")
    @Log(module = "角色信息",operate = "查询没有被删除的角色")
    @ApiOperation(value = "查询没有被删除的角色",notes = "查询没有被删除的角色")
    public Response listRoleNotRemove(){
        return Response.okData(sysRoleService.listRoleNotRemove());
    }


}
